package com.design03_behavioral.pattern16_responsibilityChains.example03;

import com.design03_behavioral.pattern16_responsibilityChains.example02.AuthService;
import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

/**
 * @ClassName Client
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/9 1:15
 */
public class Client {

    private Logger logger = Logger.getLogger("测试");

    @Test
    public void main() throws ParseException {
        AuthLink authLink = new Level3AuthLink("1000013", "王 工")
                .appendNext(new Level2AuthLink("1000012", "张 经理")
                        .appendNext(new Level1AuthLink("1000011", "段总")));


        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        //String currentDate = f.format(date);


        if (authLink != null) {
            //AuthService.auth(authLink.levelUserId, currentDate);
            authLink.doAuth(authLink.levelUserId, authLink.levelUserName, date);
        }
//        while (authLink.next != null) {
//            authLink = authLink.getNext();
//            date = new Date();
//            //currentDate = f.format(date);
//            //AuthService.auth(authLink.levelUserId, currentDate);
//            authLink.doAuth(authLink.levelUserId, authLink.levelUserName, date);
//        }


//        logger.info("测试结果：{}", JSON.toJSONString(authLink.doAuth("研发牛马", "1000998004813441", currentDate)));

        // 模拟三级负责人审批
        AuthService.auth("1000013", "1000998004813441");
//        logger.info("测试结果：{}", "模拟三级负责人审批，王工");
//        logger.info("测试结果：{}",
//                JSON.toJSONString(authLink.doAuth("研发牛马",
//                        "1000998004813441", currentDate)));


        // 模拟二级负责人审批
        AuthService.auth("1000012", "1000998004813441");
//        logger.info("测试结果：{}", "模拟二级负责人审批，张经理");
//        logger.info("测试结果：{}",
//                JSON.toJSONString(authLink.doAuth("研发牛马",
//                        "1000998004813441", currentDate)));


        // 模拟一级负责人审批
        AuthService.auth("1000011", "1000998004813441");
//        logger.info("测试结果：{}", "模拟一级负责人审批，段总");
//        logger.info("测试结果：{}",
//                JSON.toJSONString(authLink.doAuth("研发牛马",
//                        "1000998004813441", currentDate)));


    }

}
